//
//  OYCVisitorController.swift
//  WeiBo-Swift
//
//  Created by daniel on 2017/7/26.
//  Copyright © 2017年 daniel. All rights reserved.
//

import UIKit

class OYCVisitorController: UITableViewController, OYCVisitorViewDelegate{
    
    override func loadView() {
        
        let isVisitor = !OYCUserViewModel.shared.userLogon
        
        if isVisitor{
            
            switch tabBarItem.title! {
            case "首页":
                view = OYCVisitorView.visitorView(title: "关注一些人，回这里看看有什么惊喜", iconName: nil, isHome: true, delegate: self)
            case "消息":
                view = OYCVisitorView.visitorView(title: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知", iconName: "visitordiscover_image_message", isHome: false, delegate: self)
            case "发现":
                view = OYCVisitorView.visitorView(title: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过", iconName: "visitordiscover_image_message", isHome: false, delegate: self)
            case "我":
                view = OYCVisitorView.visitorView(title: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人", iconName: "visitordiscover_image_message", isHome: false, delegate: self)
            default:
                return
            }
            
            view = view as! OYCVisitorView
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupNav()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 0
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 0
    }

}


// MARK: - 设置导航栏
extension OYCVisitorController {
    
    fileprivate func setupNav() {
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "注册", style: UIBarButtonItemStyle.plain, target: self, action: #selector(OYCVisitorController.registerClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "登陆", style: UIBarButtonItemStyle.plain, target: self, action: #selector(OYCVisitorController.loginClick))
    }
    
    @objc fileprivate func registerClick() {
        print("注册")
    }
    
    @objc fileprivate func loginClick() {
        
        let authVC = OYCOAuthController()
        let nav = UINavigationController.init(rootViewController: authVC)
        
        navigationController?.present(nav, animated: true, completion: nil)
    }
    
}


// MARK: - OYCVisitorViewDelegate
extension OYCVisitorController {
    func registerBtnDidClick() {
        registerClick()
    }
    
    func loginBtnDidClick() {
        loginClick()
    }
}
